<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>账户账号 新增</title>
<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body>
		<form id="mcrCityOpen_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">最低授信等级</div>
                    <div class="field">
                        <select name="cityLvl" id="cityLvl">
                            <option value="group01">group01</option>
                            <option value="group02">group02</option>
                            <option value="group03">group03</option>
                            <option value="group04">group04</option>
                            <option value="group05">group05</option>
                            <option value="group06">group06</option>
                            <option value="group07">group07</option>
                            <option value="group08">group08</option>
                            <option value="group09">group09</option>
                            <option value="group10">group10</option>
                        </select>
                    </div>
                </div>

                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name="dataId" id="dataId" type="text" class="ui-textbox" value="${id}">
                      <input name="oldCityLvl" id="oldCityLvl" type="text" class="ui-textbox">
                      <input name="orgTypeName" id="orgTypeName" type="text" class="ui-textbox">
                      <input name="cityName" id="cityName" type="text" class="ui-textbox">
		          </div>
		        </div>
            </div>
        </form>
	<script>
		$(function() {
		   $("#mcrCityOpen_form").ligerForm({
                validate: true
           });
		  /*  if($("#dataId").val()){
			   $("#knotStarttimeStr").attr("disabled","true");
			   $("#knotStarttimeStr").removeAttr("class");
			   $("#knotStarttimeStr").attr("class","ui-textbox");
		   } */
	       initData();
		});
		
		//定义父级调用事件
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
            var ligerForm = liger.get("mcrCityOpen_form");
            var cityLvl = $("#cityLvl").val();
            var oldCityLvl = $("#oldCityLvl").val();
            var orgTypeName = $("#orgTypeName").val();
            var cityName = $("#cityName").val();
            var tips = '';
            if(parseInt(cityLvl.substring(5))<=7){
                tips = '确定将'+orgTypeName+'的'+cityName+'由最低操作评级'+oldCityLvl+'调整至'+cityLvl;
            }else{
                tips = '确定将'+orgTypeName+'的'+cityName+'由最低操作评级'+oldCityLvl+'调整至'+cityLvl+',该操作需要风控副总裁授权';
                var s = "该操作需要风控副总裁授权";
                var reg = new RegExp("(" + s + ")", "g");
                tips = tips.replace(reg, "<font color=red>$1</font>");
            }
            $.ligerDialog.confirm(tips, function (flag) {
                if(flag == false)return;
                if (!ligerForm.valid()) {
                    UIUtils.alertWarning("有验证信息未通过!");
                    return; //验证不通过，不执行以下代码
                }
                var data = ligerForm.getData();
                var dataId = $("#dataId").val();
                var url = '<%=path%>/mcr/mcrCityOpen/add.do';
                if(StringUtils.isNotEmpty(dataId)){
                    url = '<%=path%>/mcr/mcrCityOpen/modify.do';
                    data["id"]= dataId;
                }
                AjaxUtils.ajaxPost(url, data, addCallback);
            });
		}
		
		
		//新增回调
		function addCallback(msg){
			if(msg.success == 1){
				 parent.grid.reload();
				 //parent.$.ligerDialog.SQalert({content:'提示内容', SQ_type: "success"});
				 UIUtils.alertSuccess("操作成功!");
				 frameElement.dialog.close();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//修改初始化数据
		function initData(){
			var dataId = $("#dataId").val();
	    	if(StringUtils.isEmpty(dataId))return;
	    	var _url = '<%=path%>/mcr/mcrCityOpen/getById.do';
	    	AjaxUtils.ajaxGet(_url, {id:dataId}, initCallback);
    	}
		
		//初始化回调
		function initCallback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//修改时候设置页面数据
	    function setData(data){
	    	var form = new liger.get("mcrCityOpen_form");
	    	form.setData({
	    		loanId:data.loanId,
                oldCityLvl:data.cityLvl,
                orgTypeName:data.orgTypeName,
                cityName:data.cityName,
                cityLvl:data.cityLvl
	    	});
		};
	</script>

</body>
</html>